package controller

import (
	"mssgserver/constant"
	"mssgserver/net"
	"mssgserver/server/common"
	"mssgserver/server/game/logic"
	"mssgserver/server/game/model"
	"mssgserver/server/game/model/data"
)

var DefaultGeneralController = &generalController{}

type generalController struct {
}

func (g *generalController) Router(router *net.Router) {
	group := router.Group("general")
	group.AddRouter("myGenerals", g.myGenerals)
}

/*
*
我的军队列表
*/
func (g *generalController) myGenerals(req *net.WsMsgReq, rsp *net.WsMsgRsp) {
	rspObj := &model.MyGeneralRsp{}
	rsp.Body.Msg = rspObj
	rsp.Body.Code = constant.OK
	rsp.Body.Seq = req.Body.Seq
	rsp.Body.Name = req.Body.Name
	role, _ := req.Conn.GetProperty("role")
	rid := role.(*data.Role).RId
	generals, err := logic.GeneralService.MyGenerals(rid)
	if err != nil {
		rsp.Body.Code = err.(*common.MyError).Code()
		return
	}
	rspObj.Generals = generals
	rsp.Body.Msg = rspObj
}
